package com.chan.web.controller.cd;

import java.util.List;

import com.chan.common.annotation.Log;
import com.chan.common.core.controller.BaseController;
import com.chan.common.core.domain.AjaxResult;
import com.chan.common.core.page.TableDataInfo;
import com.chan.common.enums.BusinessType;
import com.chan.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chan.domain.CdProgramFile;
import com.chan.service.ICdProgramFileService;


/**
 * 附件Controller
 *
 * @author chan
 * @date 2024-04-30
 */
@Controller
@RequestMapping("/cd/programFile")
public class CdProgramFileController extends BaseController
{
    private String prefix = "cd/programFile";

    @Autowired
    private ICdProgramFileService cdProgramFileService;

    @RequiresPermissions("cd:programFile:view")
    @GetMapping()
    public String programFile()
    {
        return prefix + "/programFile";
    }
    @RequiresPermissions("cd:programFile:list")
    @GetMapping("/ck/{relate_id}/{relate_mode}")
    public String authUser(@PathVariable("relate_id") Long relate_id,@PathVariable("relate_mode") Long relate_mode, ModelMap mmap)
    {
        mmap.put("relateId", relate_id);
        mmap.put("relateMode", relate_mode);
        return prefix + "/programFile";
    }
    /**
     * 查询附件列表
     */
    @RequiresPermissions("cd:programFile:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CdProgramFile cdProgramFile)
    {
        startPage();
        List<CdProgramFile> list = cdProgramFileService.selectCdProgramFileList(cdProgramFile);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @RequiresPermissions("cd:programFile:export")
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CdProgramFile cdProgramFile)
    {
        List<CdProgramFile> list = cdProgramFileService.selectCdProgramFileList(cdProgramFile);
        ExcelUtil<CdProgramFile> util = new ExcelUtil<CdProgramFile>(CdProgramFile.class);
        return util.exportExcel(list, "附件数据");
    }

    /**
     * 新增附件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存附件
     */
    @RequiresPermissions("cd:programFile:add")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CdProgramFile cdProgramFile)
    {
        return toAjax(cdProgramFileService.insertCdProgramFile(cdProgramFile));
    }

    /**
     * 修改附件
     */
    @RequiresPermissions("cd:programFile:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CdProgramFile cdProgramFile = cdProgramFileService.selectCdProgramFileById(id);
        mmap.put("cdProgramFile", cdProgramFile);
        return prefix + "/edit";
    }

    /**
     * 修改保存附件
     */
    @RequiresPermissions("cd:programFile:edit")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CdProgramFile cdProgramFile)
    {
        return toAjax(cdProgramFileService.updateCdProgramFile(cdProgramFile));
    }

    /**
     * 删除附件
     */
    @RequiresPermissions("cd:programFile:remove")
    @Log(title = "附件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cdProgramFileService.deleteCdProgramFileByIds(ids));
    }
}
